package cn.changeforyou.web.dao.mybatis.ext.metaInfo;

import org.apache.ibatis.mapping.SqlCommandType;

/**
 * 映射器的参数类型
 *
 * @author zhyu
 * @version 1.0
 * @date 2022/2/14 20:06
 */
public enum MappedStatementParameterType {

    /**
     * 1. selectById(id);
     * 2. select();
     * 3. select(entity)
     * 4. select(condition)
     */
    selectById(SqlCommandType.SELECT, "根据id查询数据"),
    selectByEntity(SqlCommandType.SELECT, "根据实体类查询数据"),
    selectByCondition(SqlCommandType.SELECT, "根据条件类查询数据"),
    selectEmpty(SqlCommandType.SELECT, "空参数"),

    insertEntity(SqlCommandType.INSERT, "插入实体"),
    insertList(SqlCommandType.INSERT, "插入实体列表"),
    insertDto(SqlCommandType.INSERT, "插入数据传输对象"),
    insertDtoList(SqlCommandType.INSERT, "插入数据传输对象list"),

    updateEntity(SqlCommandType.UPDATE, "修改实体"),
    updateEntityIgnoreNull(SqlCommandType.UPDATE, "修改实体忽视null"),
    updateDto(SqlCommandType.UPDATE, "修改数据传输对象"),
    updateDtoIgnoreNull(SqlCommandType.UPDATE, "修改数据传输对象忽视null"),
    updateEntityByCondition(SqlCommandType.UPDATE, "通过条件类修改实体"),
    updateDtoByCondition(SqlCommandType.UPDATE, "通过条件类修改数据传输对象"),

    deleteById(SqlCommandType.DELETE, "通过主键删除"),
    deleteByEntity(SqlCommandType.DELETE, "通过entity删除"),
    ;

    MappedStatementParameterType(SqlCommandType sqlCommandType, String desc) {
        this.sqlCommandType = sqlCommandType;
        this.desc = desc;
    }

    /**
     * 大类型
     */
    private SqlCommandType sqlCommandType;
    /**
     * 描述
     */
    private String desc;

    public static boolean in(MappedStatementParameterType type, MappedStatementParameterType ... mappedStatementParameterTypes) {
        for (MappedStatementParameterType parameterType : mappedStatementParameterTypes) {
            if(type == parameterType) {
                return true;
            }
        }
        return false;
    }
}
